package com.da.javatest.niuke.baodian;

/**
 * @author chenlida
 * @date 2020/10/13 10:03
 * https://www.nowcoder.com/practice/ab79a29848d14228bb8e6b1af1c78bb7?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C68MaxSum {
    public static int getMaxSum(int[] A, int n) {
        int sum = 0;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            sum += A[i];
            if (sum > max) {
                max = sum;
            }
            if (sum < 0) {
                sum = 0;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(getMaxSum(new int[] {-79, 41, 11, -141, 39, 137}, 6));
        System.out.println(getMaxSum(new int[] {56, -88}, 2));
        System.out.println(getMaxSum(new int[] {118, 42, -2, 34, 132, 55, 60, -100, 143, -64}, 10));
    }
}
